<?php
class database {
	public $connection, $result;

	public function __construct($dbhost, $dbuser, $dbpass, $dbname){
		$this->connection = mysql_connect($dbhost, $dbuser, $dbpass);
		if($this->connection){
			$db = mysql_select_db($dbname, $this->connection);
			if(!$db){ print "DATABASE ERROR"; exit; }
		}
		else{ print "DATABASE SERVER ERROR"; exit; }
	}

	public function query($sql){
		$this->result = mysql_query($sql, $this->connection);
		if($this->result){ return true; }
		else{ return false; }
	}

	public function count(){
		if($this->result){
			$cnt = mysql_num_rows($this->result);
			if(0 < $cnt){ return true; }
			else{ return false; }
		}
	}

	public function fetch($sql){
		if($this->query($sql) && $this->count()){
			while($row = mysql_fetch_row($this->result)){ $ret[] = $row; }
			return $ret;
		}
		else{ return null; }
	}

	public function close(){
		mysql_close($this->connection);
	}
}
?>